// 路由配置信息



//引入路由组件
import Home from '@/pages/Home'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Search from '@/pages/Search'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
//引入二级路由
import MyOrder from '@/pages/Center/myOrder'
import GroupOrder from '@/pages/Center/groupOrder'


//路由懒加载
// 当打包构建应用时，JavaScript包会变得非常大，影响页面加载。如果我们能把不同路由对应的组件分割
// 成不同的代码块，然后当路由被访问的时候才加载对应组件，这样就更加高效了。
// component:()=> import('@/pages/Home')

export default [ //路由匹配规则
    { name: 'home', path: '/home', component: () => import('@/pages/Home'), meta: { show: true } }, //redirect重定向
    {
        name: 'center', path: '/center', component: Center, meta: { show: true },
        // 二级路由
        children: [
            {
                name: 'myorder', path: 'myorder', component: MyOrder,
            },
            {
                name: 'grouporder', path: 'grouporder', component: GroupOrder,
            },
            //重定向，重定向，在项目跑起来的时候，访问/，立马让他定向到首页
            {
                path: '/center',
                redirect: "/center/myorder"
            }
        ]

    }, //redirect重定向
    { name: 'login', path: '/login', component: Login, meta: { show: false } },
    { name: 'register', path: '/register', component: Register, meta: { show: false } },
    { name: 'detail', path: '/detail/:skuid?', component: Detail, meta: { show: true } },
    {
        name: 'search',
        path: '/search/:keyword?',
        component: Search,
        meta: { show: true },
        //路由组件传递props数据
        //布尔值写法：只能传毒params参数
        // props: true,
        //对象写法,额外传递参数
        // props: { a: 1, b: 1 }
        //函数写法:可以params参数、query参数，通过props传递给路由组件 
        // props: ($route) => {
        //     return {
        //         keyword: $route.params.keyword,
        //         k: $route.query.k
        //     }
        // }

    },
    { name: 'addcartsuccess', path: '/addcartsucces', component: AddCartSuccess, meta: { show: false } },
    { path: '/shopcart', component: ShopCart, meta: { show: false } },
    {
        name: 'trade', path: '/trade', component: Trade, meta: { show: true },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            // ...
            if (from.path == '/shopcart') {
                next()
            }
            else {
                next(false)
            }
        }
    },
    {
        name: 'pay', path: '/pay', component: Pay, meta: { show: true },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            // ...
            if (from.path == '/trade') {
                next()
            }
            else {
                next(false)
            }
        }
    },
    {
        name: 'paysuccess', path: '/paysuccess', component: PaySuccess, meta: { show: true },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            // ...
            if (from.path == '/pay') {
                next()
            }
            else {
                next(false)
            }
        }
    },
    //重定向，重定向，在项目跑起来的时候，访问/，立马让他定向到首页
    {
        path: '*',
        redirect: "/home"
    }
]